package com.qfhd.soft.cjzcore.User;

import com.qfhd.soft.cjzcore.Core.CJJsonUtils;
import com.qfhd.soft.cjzcore.Core.CJLogger;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class CJZUserInfo {
    public static String status_normal      = "正常";
    public static String status_blocked     = "封禁";
    public static String status_anonymity   = "匿名";
    public static String status_Internet    = "网页注册，未绑定设备";

    public static final int Sign_Type_sign  = 1;
    public static final int Sign_Type_unsign= 0;

    public void addSignLength(){
        sign_length++;
    }

    public static String getStatusString(int status){
        String statusStr    = "";
        switch (status){
            case 1:{
                statusStr   = status_normal;
            }
            break;
            case 2:{
                statusStr   = status_blocked;
            }
            break;
            case 3:{
                statusStr   = status_anonymity;
            }
            break;
            case 4:{
                statusStr   = status_Internet;
            }
            break;
            default:{
                statusStr   = status_normal;
            }
            break;
        }
        return statusStr;
    }

    public int id;

    public String device_id;

//    @SerializedName(value = "user_account", alternate = {"account"})
    public String account;

    public String wechatId;

//    @SerializedName("wx_binded")
    public boolean isBlindWechat;

    public boolean new_user;

    public boolean new_device;

    public int  user_id;

//    @SerializedName(value = "phoneNumber", alternate = {"phone_number"})
    public String phoneNumber;

    public String nickname;

    public String head_image;

    public String real_name;

    /**
     * 金币
     */
    public int score;

    /**
     * 现金
     */
    public float balance = 0f;

    /**
     * /// 状态
     * /// 1:正常
     * /// 2:封禁
     * /// 3:匿名
     * /// 4:网页注册未绑定设备信息
     */
    public int state;

    /**
     * 场景
     */
    public String scene;

    /**
     * 是否提现过
     */
//    @SerializedName("is_cashed")
    public boolean isCashed;

    /**
     * 钻石数量
     */
//    @SerializedName("diamonds")
    public int zuanshiNumber;

    /**
     * 钻石达成的成就
     */
    public List<Boolean> diamond_exc_his = new ArrayList<Boolean>(){{
        this.add(true);
        this.add(true);
        this.add(true);
    }};

    public void setDiamond_exc_his_status(int index,boolean status){
        diamond_exc_his.set(index,status);
    }

    /**
     * 每日任务完成的金币数
     */
    public int dailyScore;

    /**
     * 连续签到数
     */
    public int sign_length;

    /**
     * 1:签到
     * 0：未签到
     */
    public int signed;

    public boolean isSign(){
        if(signed == Sign_Type_sign){
            return true;
        }
        else{
            return false;
        }
    }

    public void setSign(boolean isSign){
        if(isSign){
            signed = Sign_Type_sign;
        }
        else{
            signed = Sign_Type_unsign;
        }
    }

    public static CJZUserInfo getmodelByJSON(JSONObject obj){
        CJLogger.v("UserInfo:"+obj.toString());
        CJZUserInfo userInfo = new CJZUserInfo();
        try{
            JSONObject userObj = CJJsonUtils.getJSONObjectFromKey_string(obj,"user_info");
            if(userInfo == null) return userInfo;
            userInfo.user_id = CJJsonUtils.getValueFromKey_int(userObj,"user_id");
            userInfo.account = CJJsonUtils.getValueFromKey_string(userObj,"account");
            userInfo.balance = CJJsonUtils.getValueFromKey_float(userObj,"balance");
            userInfo.dailyScore = CJJsonUtils.getValueFromKey_int(userObj,"dailyScore");
            userInfo.device_id = CJJsonUtils.getValueFromKey_string(userObj,"device_id");
            userInfo.diamond_exc_his = CJJsonUtils.getListFromKey_boolean(userObj,"diamond_exc_his");
            userInfo.head_image = CJJsonUtils.getValueFromKey_string(userObj,"head_image");
            userInfo.isBlindWechat = CJJsonUtils.getValueFromKey_boolean(userObj,"wx_binded");
            userInfo.isCashed = CJJsonUtils.getValueFromKey_boolean(userObj,"is_cashed");
            userInfo.scene = CJJsonUtils.getValueFromKey_string(userObj,"scene");
            userInfo.score = CJJsonUtils.getValueFromKey_int(userObj,"score");
            userInfo.sign_length = CJJsonUtils.getValueFromKey_int(userObj,"sign_length");
            userInfo.signed = CJJsonUtils.getValueFromKey_int(userObj,"signed");
            userInfo.state = CJJsonUtils.getValueFromKey_int(userObj,"state");
            userInfo.wechatId = CJJsonUtils.getValueFromKey_string(userObj,"wechatId");
            userInfo.phoneNumber = CJJsonUtils.getValueFromKey_string(userObj,"phone_number");
            userInfo.isCashed = CJJsonUtils.getValueFromKey_boolean(userObj,"is_cashed");
        }catch (Exception e){
            e.printStackTrace();
            CJLogger.v("CJZUserInfo e:" + e.toString());
        }
        return userInfo;
    }
}
